package com.xuecheng.content.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.api.content.teachplan.dto.TeachplanMediaDTO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.content.convert.TeachplanConvert;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.service.TeachplanMediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xuan
 */
@Slf4j
@RestController
//@RequestMapping("teachplanMediaDTO")
public class TeachplanMediaController {

    @Autowired
    private TeachplanMediaService  teachplanMediaService;

    //Feign删除所调用的拆线呢方法
    @GetMapping("/media/{mediaId}")
    RestResponse<TeachplanMediaDTO> getMediaById(@PathVariable("mediaId") Long mediaId){
        LambdaQueryWrapper<TeachplanMedia> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TeachplanMedia::getMediaId,mediaId);
        TeachplanMedia result = teachplanMediaService.getOne(wrapper);

        TeachplanMediaDTO mediaDTO = TeachplanConvert.INSTANCE.entitytwo2dto(result);
        RestResponse<TeachplanMediaDTO> response = new RestResponse<>();
        response.setResult(mediaDTO);

        return  response;

    }

}
